﻿using System;
using System.Windows;
using Budget.Silver.View;
using Castle.Windsor;
using Castle.Windsor.Installer;

namespace Budget.Silver.Core.Locator
{
    public class IoC : IDisposable
    {
        private static IWindsorContainer container;

        public static IWindsorContainer Current
        {
            get { return container; }
        }

        public IoC()
        {
            container = new WindsorContainer();
        }

        public void Install()
        {
            container.Install(FromAssembly.This());
        }

        public void Uninstall()
        {
            Dispose();
        }

        public UIElement GetRoot()
        {
            return container.Resolve<MainView>();
        }

        public void Dispose()
        {
            if (container != null)
            {
                container.Dispose();
            }

            container = null;
        }
    }
}